<!DOCTYPE html>
<html>
  <head><meta name="generator" content="Hexo 3.8.0">
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="fengzhaoyang&#39;s blog">
  <meta name="keyword" content="hexo-theme, vuejs">
  
  <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
    linux vi/vim 命令 | fzy-blog
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  <link rel="stylesheet" href="/css/style.css">
  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
  <script src="/js/qrious.js"></script>
  
  
  
  
    <!-- MathJax support START -->
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
        }
      });
    </script>

    <script type="text/x-mathjax-config">
      MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for (i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
        }
      });
    </script>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <!-- MathJax support END -->
  


</head>
<div class="wechat-share">
  <img src="/css/images/logo.png">
</div>
  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>fzy-blog</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">Home</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">Tags</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">Archives</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/project/" class="item-link">Projects</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">About</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">Home</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">Tags</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">Archives</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/project/" class="menu-link">Projects</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">About</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>linux vi/vim 命令</h2>
  <p class="post-date">2019-05-24</p>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="linux-vi-vim-命令"><a href="#linux-vi-vim-命令" class="headerlink" title="linux vi/vim 命令"></a>linux vi/vim 命令</h1><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br></pre></td><td class="code"><pre><span class="line">esc</span><br><span class="line">shift+:</span><br><span class="line">i 编辑模式</span><br><span class="line">:wq 保存退出</span><br><span class="line">:q 直接退出</span><br><span class="line">:q!强制退出</span><br><span class="line">:set nu   显示行号</span><br><span class="line">:32,100d 删除多行</span><br><span class="line"></span><br><span class="line">vi filename  打开或新建文件，并将光标置于第一行首</span><br><span class="line">vi +n filename 打开文件，并将光标置于第n行首</span><br><span class="line">vi + filename 打开文件，并将光标置于最后一行首</span><br><span class="line">vi +/pattern filename 打开文件，并将光标置于第一个与pattern匹配的串处</span><br><span class="line">vi -r filename  在上次正用vi编辑时发生系统崩溃，恢复filename</span><br><span class="line">vi filename.... filename  打开多个文件，依次进行编辑</span><br><span class="line"></span><br><span class="line">移动光标类命令</span><br><span class="line">h  光标左移一个字符</span><br><span class="line">l  光标右移一个字符</span><br><span class="line"></span><br><span class="line">space 光标右移一个字符</span><br><span class="line">Backspace 光标左移一个字符</span><br><span class="line">k或Ctrl+p 光标上移一行</span><br><span class="line">j或Ctrl+n  光标下移一行</span><br><span class="line">Enter  光标下移一行</span><br><span class="line">w或W  光标右移一个字至字首</span><br><span class="line">b或B  光标左移一个字至字首</span><br><span class="line">e或E  光标右移一个字至字尾</span><br><span class="line">)  光标移至句尾</span><br><span class="line">(  光标移至句首</span><br><span class="line">&#125; 光标移至段落开头</span><br><span class="line">&#123; 光标移至段落结尾</span><br><span class="line">nG 光标移至第n行首</span><br><span class="line">n+ 光标下移n行</span><br><span class="line">n- 光标上移n行</span><br><span class="line"><span class="meta">n$</span> 光标移至第n行尾</span><br><span class="line">H  光标移至屏幕顶行</span><br><span class="line">M  光标移至屏幕中间行</span><br><span class="line">L  光标移至屏幕最后行</span><br><span class="line">0 （注意是数字零）光标移至当前行首</span><br><span class="line"><span class="meta">$</span> 光标移至当前行尾</span><br><span class="line"></span><br><span class="line">屏幕翻滚类命令</span><br><span class="line">Ctrl+u 向文件首翻半屏</span><br><span class="line">Ctrl+d 向文件尾翻半屏</span><br><span class="line">Ctrl+f 向文件尾翻一屏</span><br><span class="line">Ctrl＋b；向文件首翻一屏</span><br><span class="line">nz 将第n行滚至屏幕顶部，不指定n时将当前行滚至屏幕顶部。</span><br><span class="line"></span><br><span class="line">插入文本类命令</span><br><span class="line">i  在光标前</span><br><span class="line">I  在当前行首</span><br><span class="line">a 光标后</span><br><span class="line">A 在当前行尾</span><br><span class="line">o 在当前行之下新开一行</span><br><span class="line">O 在当前行之上新开一行</span><br><span class="line">r 替换当前字符</span><br><span class="line">R 替换当前字符及其后的字符，直至按ESC键</span><br><span class="line">s 从当前光标位置处开始，以输入的文本替代指定数目的字符</span><br><span class="line">S 删除指定数目的行，并以所输入文本代替之</span><br><span class="line">ncw或nCW 修改指定数目的字</span><br><span class="line">nCC 修改指定数目的行</span><br><span class="line"></span><br><span class="line">删除命令</span><br><span class="line">ndw或ndW 删除光标处开始及其后的n-1个字</span><br><span class="line">do 删至行首</span><br><span class="line"><span class="meta">d$</span> 删至行尾</span><br><span class="line">ndd 删除当前行及其后n-1行</span><br><span class="line">x或X 删除一个字符，x删除光标后的，而X删除光标前的</span><br><span class="line">Ctrl+u 删除输入方式下所输入的文本</span><br><span class="line"></span><br><span class="line">搜索及替换命令</span><br><span class="line">/pattern 从光标开始处向文件尾搜索pattern</span><br><span class="line">?pattern 从光标开始处向文件首搜索pattern</span><br><span class="line">n 在同一方向重复上一次搜索命令</span><br><span class="line">N 在反方向上重复上一次搜索命令</span><br><span class="line"> s/p1/p2/g 将当前行中所有p1均用p2替代</span><br><span class="line"> n1,n2s/p1/p2/g 将第n1至n2行中所有p1均用p2替代</span><br><span class="line"> g/p1/s//p2/g 将文件中所有p1均用p2替换</span><br><span class="line"></span><br><span class="line">选项设置</span><br><span class="line">all 列出所有选项设置情况</span><br><span class="line">term 设置终端类型</span><br><span class="line">ignorance 在搜索中忽略大小写</span><br><span class="line">list 显示制表位(Ctrl+I)和行尾标志（$)</span><br><span class="line">number 显示行号</span><br><span class="line">report 显示由面向行的命令修改过的数目</span><br><span class="line">terse 显示简短的警告信息</span><br><span class="line">warn 在转到别的文件时若没保存当前文件则显示NO write信息</span><br><span class="line">nomagic 允许在搜索模式中，使用前面不带“\”的特殊字符</span><br><span class="line">nowrapscan 禁止vi在搜索到达文件两端时，又从另一端开始</span><br><span class="line">mesg 允许vi显示其他用户用write写到自己终端上的信息</span><br><span class="line"></span><br><span class="line">最后行方式命令</span><br><span class="line"> n1,n2 co n3 将n1行到n2行之间的内容拷贝到第n3行下</span><br><span class="line"> n1,n2 m n3 将n1行到n2行之间的内容移至到第n3行下</span><br><span class="line"> n1,n2 d  将n1行到n2行之间的内容删除</span><br><span class="line"> w  保存当前文件</span><br><span class="line"> e filename 打开文件filename进行编辑</span><br><span class="line"> x 保存当前文件并退出</span><br><span class="line"> q 退出vi</span><br><span class="line"> q! 不保存文件并退出vi</span><br><span class="line"> !command 执行shell命令command</span><br><span class="line"> n1,n2 w!command 将文件中n1行至n2行的内容作为command的输入并执行之，若不指定n1，n2，则表示将整个文件内容作为command的输入</span><br><span class="line"> r!command 将命令command的输出结果放到当前行</span><br></pre></td></tr></table></figure>
</section>
    <!-- Tags START -->
    
    <div class="tags">
      <span>Tags:</span>
      
  <a href="/tags#Linux">
    <span class="tag-code">Linux</span>
  </a>

    </div>
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/2019/05/24/Linux/linuxmysql配置远程连接数据库/">
        <span class="nav-arrow">← </span>
        
          linux mysql 配置远程连接数据库
        
      </a>
    
    
      <a class="nav-right" href="/2019/05/24/Linux/linuxmysql常用脚本/">
        
          linux mysql 常用脚本
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
    <div class="money-like">
      <div class="reward-btn">
        赏
        <span class="money-code">
          <span class="alipay-code">
            <div class="code-image"></div>
            <b>使用支付宝打赏</b>
          </span>
          <span class="wechat-code">
            <div class="code-image"></div>
            <b>使用微信打赏</b>
          </span>
        </span>
      </div>
      <p class="notice">若你觉得我的文章对你有帮助，欢迎点击上方按钮对我打赏</p>
    </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
    <div class="qrcode">
      <canvas id="share-qrcode"></canvas>
      <p class="notice">扫描二维码，分享此文章</p>
    </div>
    
    <!-- 二维码 END -->
    
    <!-- No Comment -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
  <aside class="catalog-container">
  <div class="toc-main">
    <strong class="toc-title">Catalog</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#linux-vi-vim-命令"><span class="toc-nav-text">linux vi/vim 命令</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'https://fengzhaoy.github.io/2019/05/24/Linux/linuxvi命令/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function () {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function () {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="' + src +
          '" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function () {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


<script>
  var qr = new QRious({
    element: document.getElementById('share-qrcode'),
    value: document.location.href
  });
</script>





    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
  <p class="copyright">
    &copy; 2019
  </p>
</footer>

<script>
  function async (u, c) {
    var d = document,
      t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) {
      o.addEventListener('load', function (e) {
        c(null, e);
      }, false);
    }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async ("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function () {
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async ("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function () {
    $('figure pre').each(function (i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>
<!-- Baidu Tongji -->

<script src="/js/script.js"></script>
  </body>
</html>